package com.lfp.controller;

import com.lfp.config.rabbitmq.ConfirmConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @Description TODO
 * @Author lfp
 * @Date 2022/7/19
 * @Version 1.0
 */
@Slf4j
@RestController
@Api(tags = "发布确认接口管理")
@RequestMapping("confirm")
public class ConfirmController {
    @Autowired
    private RabbitTemplate rabbitTemplate;



    @ApiOperation("发送确认消息")
    @PostMapping("sendConfirmMessage/{message}")
    public void sendConfirmMessage(@PathVariable String message){
        //模拟业务数据Id
        String businessId = UUID.randomUUID().toString().replace("-","");
        CorrelationData correlationData = new CorrelationData(businessId);

        rabbitTemplate.convertAndSend(
                ConfirmConfig.CONFIRM_EXCHANGE_NAME,
                ConfirmConfig.CONFIRM_ROUTING_KEY,
                message,
                correlationData//传递额外参数
        );
        log.info("消息已发送，内容为：{}",message);
    }
}
